package com.gdth.bank.widget;

import java.util.HashMap;
import java.util.Map;

import com.gdth.bank.utils.Callback;
import com.gdth.bank.utils.WebViewUtil;
import com.gdth.utils.webViewUtils;
import com.gdth.widget.webview.BaseWebViewClient;
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Bitmap;
import android.webkit.WebView;

@SuppressLint("NewApi")
public class BankWebViewClient extends BaseWebViewClient{
	
	private Context context;
	Callback callback;
	public BankWebViewClient(Context context,Callback callback) {
		this.context = context;
		this.callback = callback;
	
	}
	
	@Override 
    public boolean shouldOverrideUrlLoading(WebView webview, String url) {   
//		Intent intent = new Intent(context, WebViewActivity.class);
//		intent.putExtra("path", url);
//		intent.putExtra("name", "dd");
//		context.startActivity(intent);
//
//        return false; 
//		
//		if(url.contains("attestation=")) {
//			callback.callbacb();
//			return super.shouldOverrideUrlLoading(webview, url);
//		}else {
//			
//			webview.loadUrl(webViewUtils.NewUrl(url));
//			return true;
//		}
		
		
		Map<String, String> extraHeaders = new HashMap<String, String>();
	     extraHeaders.put("attestation", webViewUtils.getHeadParam());
	     webview.getSettings().setUserAgentString("okhttp viewAction");
	  webview.loadUrl(url,extraHeaders);
	  return true;
    }
	
	@Override
	public void onPageStarted(WebView view, String url, Bitmap favicon) {
		callback.callbacb();
		super.onPageStarted(view,url, favicon);
	}
	


	@Override
	public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
		super.onReceivedError(view, errorCode, description, failingUrl);
		//这里进行无网络或错误处理，具体可以根据errorCode的值进行判断，做跟详细的处理。
		view.loadUrl(WebViewUtil.ERROR_URL);
	}
	
	
}
